﻿#region

using System.Collections.Generic;
using System.Text.RegularExpressions;

#endregion


namespace OMS.Ice.T4Generator.Syntax
{
    public enum Expression
    {
        Comment,
        Directive,
        StandardControlBlock,
        FeatureControlBlock,
        ExpressionControlBlock
    }

    public class T4Syntax
    {
        public T4Syntax()
        {
            Expressions = new Dictionary<Expression, Regex>
                          {
                              {
                                  Expression.Comment, new Regex( "<#--( |\\t)*\\r?\\n?(?<comment>(?s:.*?))( |\\t)*\\r?\\n?--#>(\\w*\\r?\\n)?",
                                                                 RegexOptions.Compiled )
                                  },
                              {
                                  Expression.Directive, new Regex(
                                  @"<#@\s+(?<type>\w+)(\s+(?<key>\w+)\s*=[""'](?<value>[^""']*)[""'])*\s*#>(\w*\r?\n)?",
                                  RegexOptions.Compiled )
                                  },
                              {
                                  Expression.StandardControlBlock,
                                  new Regex( "<#(?![@=$#%+]|--)\\s*\\r?\\n?(?<content>[^=]((.|\\r|\\n)*?(<#=(.|\\r|\\n)*?#>)?)*)#>(\\w*\\r?\\n)?",
                                             RegexOptions.Compiled )
                                  },
                              {
                                  //Expression.FeatureBlock, new Regex( "<#\\+\\s*\\r?\\n?(?<content>((.|\\r|\\n)*?(\\w*@[^\\r\\n]*\\r?\\n)*)*)#>(\\w*\\r?\\n)?",
                                  Expression.FeatureControlBlock, new Regex( "<#\\+(?<content>(\\s*.[^#>])*)#>(\\w*\\r?\\n)?",
                                                                      RegexOptions.Compiled )
                                  },
                              {
                                  Expression.ExpressionControlBlock, new Regex( "<#=\\s*(?<content>(.[^#>])*)\\s*#>",
                                                                            RegexOptions.Compiled )
                                  },
                          };
        }

        public IDictionary<Expression, Regex> Expressions { get; private set; }
    }
}